<script>
    var items = <?= $items; ?>;
    var preview = <?= isset($_GET['preview']) ? 1 : 0; ?>;
</script>
<?php
    $this->load->view('parts/google_map', array('googlemap' => $googlemap));

    if (!isset($_GET['preview'])) {

    $build_G = $_GET;
    if ($build_G['dest_hot'] == "")
    $build_G['dest_hot'] = -1;

    unset($build_G['lang']);

    $build_GET = http_build_query($build_G);
    }else {
    $build_GET = '&preview=1';
    }
?>

<div class="details search-details">

    <?php $this->load->view('booking/search-box') ?>

    <div style="clear:both"></div>

    <div class="side-google-map googlebox" style=""> <!-- GOOGLE MAP PREVIEW GOES HERE  -->
        <div class="action"><a href="javascript:" data-id="ALL" class="btn googlebox show_map"><?= lang('hotell.show_map_cap') ?> >></a></div>
    </div>

    <div>
        <? $this->load->view('parts/filter') ?>
    </div>

</div>

<div class="hotels-list">
    <?php
        $debug_attributes = false;
    ?>


    <div class="display"><?= lang('hotell.hotels_available') ?>: <span class="hotels-count"><?= count($results) ?> <span></div>

                <div class="clearfix">

                    <div class="form-horizontal form-col clearfix fixcol right sort-by">

                        <div class="col">

                            <label><?= lang('hotell.sort_by_upper') ?></label>

                            <select name="sort_by" id="sort_by" class="dropdownized">
                                <option value="recommended"><?= lang('hotell.recommended') ?></option>
                                <? if (!isset($_GET['preview'])): ?>
                                <option value="price"><?= lang('hotell.price') ?></option>
                                <? endif; ?>
                                <option value="number_of_stars"><?= lang('hotell.number_of_stars'); ?></option>
                                <option value="object_name"><?= lang('name'); ?></option>
                            </select>

                        </div>

                    </div>

                    <div class="breadcrumb clearfix">
                        <div class="left"><a href="javascript:" class="search_term"><?= lang('hotell.search_term') ?>:</a></div>
                        <div class="left">&nbsp;&nbsp;</div>
                        <div class="left active">"<?= $_GET['dest_hot']; ?>"</div>
                    </div>

                </div>

                <ul id="list">
                    <?php
                        $index_22 = 0;
                        $i = 0;
                        if ($results)
                        foreach ($results as $object):
                        $link = base_url('hotel_id=' . $object->object_ID . '&' . http_build_query($_GET));
                        $bt_title = lang('hotell.book_now');

                        $obj_name = URLify::filter($object->object_name);
                        $href = base_url('accommodation/' . $obj_name . '-' . $object->object_ID . '?' . $build_GET . '&room_id=' . $object->rooms[0]->room_ID);
                        $link = $href;
                    ?>
                    <li class="js_item" id="box-<?= $object->object_ID ?>" style="display: block" data-id="<?= $object->object_ID ?>">

                        <div class="one_object clearfix">

                            <div class="photo">

                                <?php $preview = $host_url . $object->photo_path . '/thumb_454x340/' . $object->photo_name; ?>
                                <?php $thumbnail = $host_url . $object->photo_path . '/thumb_200x150/' . $object->photo_name; ?>

                                <a href="<?= $preview ?>" class="preview" title="<?= $object->object_name; ?>" onClick="return false;">
                                    <img src="<?= $thumbnail ?>" alt="<?= $object->object_name; ?>" />
                                </a>

                            </div>

                            <div class="holder" style="<? if ($debug_attributes) echo 'height:auto;'; ?> ">


                                <div class="review_float">

                                    <? if ($object->avg_reviews_score != 0): ?>

                                    <div class="big_review_score">
                                        <? //$this->firephp->log((string) number_format($object->avg_reviews_score, 1));   ?>

                                        <?= lang((string) number_format($object->avg_reviews_score, 1)) ?>,  <?= (string) number_format($object->avg_reviews_score, 1); ?>

                                    </div>

                                    <span class="score_from_number_of_reviews"><?= lang('hotell.score_from') ?> <strong class="count"><?= $object->total_reviews ?></strong> <?= lang('hotell.reviews') ?><? if ($object->total_reviews > 1 && $this->lang->lang() == 'en') echo 's'; ?></span>

                                    <? endif; ?>

                                </div>

                                <h3>

                                    <a href="<?= $link; ?>" title="<?= $object->object_name; ?>, <?= $object->destination_name; ?>"><?= $object->object_name; ?></a>

                                    <? if ($object->object_number_of_stars != ""): ?>
                                    <span class="hotel-star star_<?= $object->object_number_of_stars ?>" title="<?= $object->object_number_of_stars ?> stars hotel">&nbsp;</span>
                                    <? endif; ?>


                                    <!--TODO dodati pravi properti smart deal umjesto object_name kada baza bude spremna -->

                                    <? if (isset($object->object_smart_deal) && $object->object_smart_deal != ""): ?>

                                    <div class="smart-deal" title="">Recommended</div>

                                    <? endif; ?>


                                </h3>

                                <div class="destination">
                                    <?= $object->destination_name; ?>

                                    <?
                                    if (isset($object->object_x_coordinate) && $object->object_x_coordinate != ""):
                                    if (isset($object->object_y_coordinate) && $object->object_y_coordinate != ""):
                                    ?>

                                    <a data-id="<?= $object->object_ID ?>" title="<?= $object->object_name; ?>, <?= $object->destination_name; ?> - <?= lang('hotell.show_map') ?>" class="show_map" href="javascript:"><?= lang('hotell.show_map') ?></a>
                                    <?
                                    $index_22++;
                                    endif;
                                    ?>
                                    <? endif; ?>

                                </div>

                                <div class="object_info">

                                    <?
                                    $str = clean_html($object->object_info);
                                    //$this->firephp->log($str);
                                    $lng = 150;
                                    if ($this->lang->lang() == 'ru')
                                    $lng = 130;
                                    if (mb_strlen($str) > $lng) {
                                    $str = mb_substr($str, 0, $lng) . '...';
                                    }
                                    echo $str;
                                    ?>

                                    <a href="<?= $link ?>" class="more"><?= lang('hotell.more') ?> >></a>

                                </div>

                                <div class="action"><a href="<?= $link ?>" class="btn"><?= $bt_title ?></a></div>

                            </div>

                        </div>

                        <div class="table-holder">
                            <table class="table table-condensed table-hover rooms">
                                <tbody>

                                    <?php
                                        foreach ($results[$i]->rooms as $room):
                                        $href_room = base_url('accommodation/' . $obj_name . '-' . $results[$i]->object_ID . '?' . $build_GET . '&room_id=' . $room->room_ID);
                                        $person_s = $room->room_max_person > 1 ? lang('res.persons') : lang('res.person');

                                        if ($this->lang->lang() == 'me'):

                                        if ($room->room_max_person == 1)
                                        $person_s = lang('res.person');
                                        else if ($room->room_max_person >= 2 && $room->room_max_person <= 4)
                                        $person_s = lang('res.persone');
                                        else
                                        $person_s = lang('res.persons');

                                        endif;

                                        /*                        $this->firephp->log('room.'.underscore($room->room_type_name)); */
                                    ?>
                                    <tr>
                                        <td>
                                            <a href="<?= $href_room ?>">

                                                <?= lang('room.' . underscore($room->room_type_name)); ?> <span class="gray">(<?= $room->room_description ?></span>&nbsp;<?= lang('form.for'); ?> <?= $room->room_max_person ?> <?= $person_s ?>)

                                            </a>

                                            <?= $room->service_name ?>

                                        </td>
                                        <td class="price"><? if (!isset($_GET['preview'])) echo $room->selling_total . currency_sign(); ?> </td>


                                    </tr>
                                    <? endforeach; ?>

                                </tbody>
                            </table>
                        </div>


                        <?
                        $i++;
                        endforeach;
                        ?>
                    </li>
                </ul>

                </div>





                <div style="clear:both"></div>